package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.usian.pojos.User;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;

import java.util.Optional;

public class Comsumer {
    @KafkaListener(topics = "{hello-kafka}")
    public void receiverMessage(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            Object value = record.value();
            System.out.println(value);
            User user= JSON.parseObject((String) value, User.class);
            System.out.println(user.toString());
        }
    }

}
